---
layout: "default"
title: "IntegerArithmeticType"
description: "Swift documentation for 'IntegerArithmeticType': The common requirements for types that support integer arithmetic."
keywords: "IntegerArithmeticType,protocol,swift,documentation,%,*,+,/,<,<=,==,>,>=,-,addWithOverflow,divideWithOverflow,multiplyWithOverflow,remainderWithOverflow,subtractWithOverflow,toIntMax"
root: "/v1.2"
---

<div class="intro-declaration"><code class="language-swift">protocol IntegerArithmeticType</code></div>

<div class="discussion comment">
    <p>The common requirements for types that support integer arithmetic.</p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">Comparable, Equatable, _Comparable, _IntegerArithmeticType</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>






<h3>Static Methods</h3>
<div class="declaration inherited" id="func-addwithoverflow__">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-addwithoverflow__">static func addWithOverflow(<wbr>_:<wbr>_:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-addwithoverflow__"><div class="p">
    <p>Add <code>lhs</code> and <code>rhs</code>, returning a result and a <code>Bool</code> that is
true iff the operation caused an arithmetic overflow.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">static func addWithOverflow(lhs: Self, _ rhs: Self) -&gt; (Self, overflow: Bool)</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/_IntegerArithmeticType/"><code>_IntegerArithmeticType</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-dividewithoverflow__">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-dividewithoverflow__">static func divideWithOverflow(<wbr>_:<wbr>_:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-dividewithoverflow__"><div class="p">
    <p>Divide <code>lhs</code> and <code>rhs</code>, returning a result and a <code>Bool</code> that is
true iff the operation caused an arithmetic overflow.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">static func divideWithOverflow(lhs: Self, _ rhs: Self) -&gt; (Self, overflow: Bool)</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/_IntegerArithmeticType/"><code>_IntegerArithmeticType</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-multiplywithoverflow__">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-multiplywithoverflow__">static func multiplyWithOverflow(<wbr>_:<wbr>_:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-multiplywithoverflow__"><div class="p">
    <p>Multiply <code>lhs</code> and <code>rhs</code>, returning a result and a <code>Bool</code> that is
true iff the operation caused an arithmetic overflow.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">static func multiplyWithOverflow(lhs: Self, _ rhs: Self) -&gt; (Self, overflow: Bool)</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/_IntegerArithmeticType/"><code>_IntegerArithmeticType</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-remainderwithoverflow__">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-remainderwithoverflow__">static func remainderWithOverflow(<wbr>_:<wbr>_:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-remainderwithoverflow__"><div class="p">
    <p>Divide <code>lhs</code> and <code>rhs</code>, returning the remainder and a <code>Bool</code> that is
true iff the operation caused an arithmetic overflow.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">static func remainderWithOverflow(lhs: Self, _ rhs: Self) -&gt; (Self, overflow: Bool)</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/_IntegerArithmeticType/"><code>_IntegerArithmeticType</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-subtractwithoverflow__">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-subtractwithoverflow__">static func subtractWithOverflow(<wbr>_:<wbr>_:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-subtractwithoverflow__"><div class="p">
    <p>Subtract <code>lhs</code> and <code>rhs</code>, returning a result and a <code>Bool</code> that is
true iff the operation caused an arithmetic overflow.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">static func subtractWithOverflow(lhs: Self, _ rhs: Self) -&gt; (Self, overflow: Bool)</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/_IntegerArithmeticType/"><code>_IntegerArithmeticType</code></a>    
</div></div>
</div>

<h3>Instance Methods</h3>
<div class="declaration" id="func-pct_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pct_rhs_">func %(<wbr>_:<wbr>rhs:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-pct_rhs_"><div class="p">
    <p>Divide <code>lhs</code> and <code>rhs</code>, returning the remainder and trapping in case of
arithmetic overflow (except in -Ounchecked builds).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %(lhs: Self, rhs: Self) -&gt; Self</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-star_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-star_rhs_">func *(<wbr>_:<wbr>rhs:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-star_rhs_"><div class="p">
    <p>Multiply <code>lhs</code> and <code>rhs</code>, returning a result and trapping in case of
arithmetic overflow (except in -Ounchecked builds).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func *(lhs: Self, rhs: Self) -&gt; Self</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pls_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pls_rhs_">func +(<wbr>_:<wbr>rhs:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-pls_rhs_"><div class="p">
    <p>Add <code>lhs</code> and <code>rhs</code>, returning a result and trapping in case of
arithmetic overflow (except in -Ounchecked builds).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func +(lhs: Self, rhs: Self) -&gt; Self</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-slash_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-slash_rhs_">func /(<wbr>_:<wbr>rhs:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-slash_rhs_"><div class="p">
    <p>Divide <code>lhs</code> and <code>rhs</code>, returning a result and trapping in case of
arithmetic overflow (except in -Ounchecked builds).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func /(lhs: Self, rhs: Self) -&gt; Self</code>
    
    
</div></div>
</div>
<div class="declaration inherited" id="func-lt_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-lt_rhs_">func &lt;(<wbr>_:<wbr>rhs:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-lt_rhs_"><div class="p">
    <p>A <a href="http://en.wikipedia.org/wiki/Total_order#Strict_total_order">strict total order</a>
over instances of <code>Self</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func &lt;(lhs: Self, rhs: Self) -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/_Comparable/"><code>_Comparable</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-lteq_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-lteq_rhs_">func &lt;=(<wbr>_:<wbr>rhs:)</a>
        
<div class="comment collapse" id="comment-func-lteq_rhs_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">func &lt;=(lhs: Self, rhs: Self) -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Comparable/"><code>Comparable</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-eqeq_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-eqeq_rhs_">func ==(<wbr>_:<wbr>rhs:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-eqeq_rhs_"><div class="p">
    <p>Return true if <code>lhs</code> is equal to <code>rhs</code>.</p>

<p><strong>Equality implies substitutability</strong>.  When <code>x == y</code>, <code>x</code> and
<code>y</code> are interchangeable in any code that only depends on their
values.</p>

<p>Class instance identity as distinguished by triple-equals <code>===</code>
is notably not part of an instance&#39;s value.  Exposing other
non-value aspects of <code>Equatable</code> types is discouraged, and any
that <em>are</em> exposed should be explicitly pointed out in
documentation.</p>

<p><strong>Equality is an equivalence relation</strong></p>

<ul><li><code>x == x</code> is <code>true</code></li><li><code>x == y</code> implies <code>y == x</code></li><li><code>x == y</code> and <code>y == z</code> implies <code>x == z</code></li></ul>

<p><strong>Inequality is the inverse of equality</strong>, i.e. <code>!(x == y)</code> iff
<code>x != y</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func ==(lhs: Self, rhs: Self) -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Equatable/"><code>Equatable</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-gt_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-gt_rhs_">func &gt;(<wbr>_:<wbr>rhs:)</a>
        
<div class="comment collapse" id="comment-func-gt_rhs_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">func &gt;(lhs: Self, rhs: Self) -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Comparable/"><code>Comparable</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-gteq_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-gteq_rhs_">func &gt;=(<wbr>_:<wbr>rhs:)</a>
        
<div class="comment collapse" id="comment-func-gteq_rhs_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">func &gt;=(lhs: Self, rhs: Self) -&gt; Bool</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/Comparable/"><code>Comparable</code></a>    
</div></div>
</div>
<div class="declaration" id="func-mns_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-mns_rhs_">func -(<wbr>_:<wbr>rhs:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-mns_rhs_"><div class="p">
    <p>Subtract <code>lhs</code> and <code>rhs</code>, returning a result and trapping in case of
arithmetic overflow (except in -Ounchecked builds).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func -(lhs: Self, rhs: Self) -&gt; Self</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-tointmax">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-tointmax">func toIntMax()</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-tointmax"><div class="p">
    <p>Explicitly convert to <code>IntMax</code>, trapping on overflow (except in
-Ounchecked builds).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func toIntMax() -&gt; IntMax</code>
    
    
</div></div>
</div>


